package com.ruijie.autotest.log.validation.hangzhoudewangxin.IMCMP;

import com.minelx.landisk.filesystem.Paths;
import com.minelx.landisk.filesystem.core.Directory;
import com.minelx.landisk.filesystem.core.File;
import com.ruijie.autotest.log.common.crypto.AES;
import com.ruijie.autotest.log.common.crypto.AESSha1Algorithm;
import com.ruijie.autotest.log.common.crypto.CBC;
import com.ruijie.autotest.log.common.crypto.Padding;
import com.ruijie.autotest.log.impl.parse.ColumnsAndValuesParser;
import com.ruijie.autotest.log.impl.parse.GridColumnsParser;
import com.ruijie.autotest.log.impl.parse.LinesParser;
import com.ruijie.autotest.log.impl.parse.ReduceEndCellsParser;
import com.ruijie.autotest.log.validation.hangzhoudewangxin.WIFILOGOUT.SingleValuesFileToTable;
import com.ruijie.autotest.log.validation.hangzhouxiruan.CompositeColumnVerification;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;

import static com.minelx.landisk.filesystem.core.File.byExtension;

@SpringBootApplication
public class IMCMPTest {

	private static final String PASSWORD = "12345678";

	private static final String IV_PASSWORD = "vg3kh4zv$u3arc1w";

	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext context = SpringApplication.run(IMCMPTest.class, args);

		ColumnsAndValuesParser columnsAndValuesParser = new ColumnsAndValuesParser(
				new GridColumnsParser(" ", 0), new LinesParser("\r\n|\n"), new ReduceEndCellsParser("\u0001"));
		SingleValuesFileToTable fileToTable = new SingleValuesFileToTable(columnsAndValuesParser, Paths.of("/C:/Users/123/ZYH_HOME/Projects/IdeaProjects/NetSupervisor/src/test/resources/mappings/hangzhoudewangxin/IMCMP/columns.txt"));
//		Verification verification = new Verification(context);

		List<File> decryptedFiles = AES.decryptedFiles(rawFiles(), CBC.create(new AESSha1Algorithm(), PASSWORD, IV_PASSWORD, Padding.PKCS_5_PADDING).cryptoFactory().decryption());
		CompositeColumnVerification manyVerification = new CompositeColumnVerification(context, fileToTable.mapToTables(decryptedFiles));
		manyVerification.verify();

//		for (File each : decryptedFiles) {
//			verification.verify(fileToTable.tableFromFile(each));
//		}
		System.out.println("we done.");
	}

	private static List<File> rawFiles() {
		Directory rootDirectory = Paths.root("/D:/FTP/杭州德网信/$FTP/IMCMP/20210107");
		return rootDirectory.childrenFiles()
				.filter(which -> !which.getName().startsWith("decrypted_")) // not starts with "decrypted_"
				.filter(byExtension("zip")).all();
	}
}
